/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Modele;

import java.util.Observable;

/**
 *
 * @author david
 */
public class Case extends Observable{
    
    public static enum Etat_case { VIDE , PION_BLANC , PION_NOIR , DAME_BLANC, DAME_NOIRE, SELECTIONNER};
    
    
    private Etat_case etat;    
    private int pos;
    private Pion pion;
    
    public Case(int pos){ 
        this.pos = pos;
        etat = Etat_case.VIDE;
        setEtat();
    }

    public Pion getPion() {
            return pion;
    }

    public void setPion(Pion pion) {            
                this.pion = pion;
                setEtat();            
    }
    
    public void setSelectionner(boolean selection){
        if(selection == true){
                etat = Etat_case.SELECTIONNER;
                this.setChanged();
                this.notifyObservers(etat);
        }else
            setEtat();
    }
    
    private void setEtat(){
        
        if( pion == null )
            etat = Etat_case.VIDE;        
        else if(pion.getCouleur() == Pion.CouleurPion.BLANC){
            
            if(!pion.isDame())  {   etat = Etat_case.PION_BLANC; }
            else                {   etat = Etat_case.DAME_BLANC; }
            
            
        }else if(pion.getCouleur() == Pion.CouleurPion.NOIR){
            
            if(!pion.isDame())  { etat = Etat_case.PION_NOIR; }
            else                { etat = Etat_case.DAME_NOIRE;}
            
        }else   { etat = Etat_case.VIDE; }
        
        this.setChanged();
        this.notifyObservers(etat);
    }
    
    public Etat_case getEtat(){ return etat; }
    
}
